package com.ess.project.examine.record.compute;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 成绩评定
 * 体型不合格、任一单项课目成绩未达到及格分，个人军事体育训练成绩为不及格
 * @Date: Created in 7:45 下午 2021/3/7
 * @Author: daihui
 * @Modified By:
 */
public class EvaluateExamineStrategy implements BaseExamine<Integer> {

    private static final Map<String, Integer[]> DIC_DATA = new HashMap<>(6);

    static {
        initDicData();
    }

    private static void initDicData(){
        Integer[] firstKindLevelScore = {260, 340, 380, 440, 480, 500};
        Integer[] secondKindLevelScore = {240, 320, 360, 440, 480, 500};
        Integer[] thirdKindLevelScore = {220, 300, 340, 440, 480, 500};
        DIC_DATA.put(FIRST_KIND, firstKindLevelScore);
        DIC_DATA.put(SECOND_KIND, secondKindLevelScore);
        DIC_DATA.put(THIRD_KIND, thirdKindLevelScore);
    }

    @Override
    public Object compute(Object args, String bodilyForm, Integer... grade) {
        String evaluateResult = "不及格";
        String personnelCategory = (String) args;
        boolean qualified = false;
        if (grade.length == 5) {
            int threeKmScore = grade[0];
            int threeTermScore = grade[1];
            int situp = grade[2];
            int snakeRun = grade[3];
            int totalScore = grade[4];

            if (FIRST_KIND_MESSAGE.equals(personnelCategory)) {
                qualified = QUALIFIED_MESSAGE.equals(bodilyForm)
                        && threeKmScore >= FIRST_KIND_PASS_SCORE
                        && threeTermScore >= FIRST_KIND_PASS_SCORE
                        && situp >= FIRST_KIND_PASS_SCORE
                        && snakeRun >= FIRST_KIND_PASS_SCORE;
            } else if (SECOND_KIND_MESSAGE.equals(personnelCategory)) {
                qualified = QUALIFIED_MESSAGE.equals(bodilyForm)
                        && threeKmScore >= SECOND_KIND_PASS_SCORE
                        && threeTermScore >= SECOND_KIND_PASS_SCORE
                        && situp >= SECOND_KIND_PASS_SCORE
                        && snakeRun >= SECOND_KIND_PASS_SCORE;
            } else if (THIRD_KIND_MESSAGE.equals(personnelCategory)) {
                qualified = QUALIFIED_MESSAGE.equals(bodilyForm)
                        && threeKmScore >= THIRD_KIND_PASS_SCORE
                        && threeTermScore >= THIRD_KIND_PASS_SCORE
                        && situp >= THIRD_KIND_PASS_SCORE
                        && snakeRun >= THIRD_KIND_PASS_SCORE;
            }

            if (!qualified) {
                return evaluateResult;
            }
            Integer[] arr = DIC_DATA.get(PersonnelKindEnum.getKey(personnelCategory));
            evaluateResult = BaseExamine.evaluate(totalScore, arr);
        }
        return evaluateResult;
    }

}
